from tortoise import fields, models
from models.user import User
from models.products import Product


class History(models.Model):
    id = fields.IntField(pk=True)
    user = fields.ForeignKeyField("models.User", related_name="histories")
    product = fields.ForeignKeyField("models.Product", related_name="histories", null=True)
    created_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_time = fields.DatetimeField(auto_now=True, description="更新时间")
    browse_time = fields.DatetimeField(auto_now_add=True, description="浏览时间")

    class Meta:
        table = "history"
